<?php
error_reporting(0);
include 'JSSDK.class.php';
include_once("SDKRuntimeException.php");
include_once("WxPayConfPub.php");
include_once("CommonUtilPub.php");
include_once("WxpayClientPub.php");
include_once("UnifiedOrderPub.php");
$appid = "wxf56864238b4b5ae8";
$appsecret = "e6d073ee0b148ccdd8c0e75509ef61b3";
$jssdk = new JSSDK($appid, $appsecret);
$signPackage = $jssdk->getSignPackage();
$nonceStr = $signPackage["nonceStr"];
$timestamp = $signPackage["timestamp"];

$unifiedOrder = new UnifiedOrderPub();
$openid = $_GET["openid"];
$unifiedOrder->setParameter("openid",$openid); //用户openId
$goodname = "商品"; //"11";//$_GET["goodname"];
$total_fee = $_GET["total_fee"];
$out_trade_no = $_GET["out_trade_no"];//"1234567890";


$unifiedOrder->setParameter("body", $goodname); //商品描述，文档里写着不能超过32个字符，否则会报错，经过实际测试，临界点大概在128左右，稳妥点最好按照文档，不要超过32个字符$_GET["total_fee"]*
$unifiedOrder->setParameter("out_trade_no", $out_trade_no); //商户订单号 
$unifiedOrder->setParameter("total_fee", $total_fee*100 /** 100*/); //总金额,单位为分
$unifiedOrder->setParameter("notify_url","https://csynspsc.kaopu58.com/index.php/index/index/notify"); //通知地址 
$unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型
$unifiedOrder->setParameter("nonce_str", $nonceStr); //随机字符串
$prepayId = $unifiedOrder->getPrepayId();
// 计算paySign
$payPackage = array(
    "appId" => $appid,
    "nonceStr" => $nonceStr,
    "package" => "prepay_id=" . $prepayId,
    "signType" => "MD5",
    "timeStamp" =>(string)$timestamp);
$paySign = $unifiedOrder->getSign($payPackage);
$payPackage['paySign'] = $paySign;


echo json_encode($payPackage);
?>